﻿using Surveying;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GIS_SpatialAnalyst
{
    public class Delauny
    {
        public Edge begin_edge;

    }
    public class Edge:Line
    {
        public bool useful=true;
        public Triangle ownerTriangle;
        private Edge eaqalEdge;

        public Edge EqualEdge
        {   
            get { return eaqalEdge; }
        }

        public bool EqualWith(Edge edge)
        {
            var samePoints = point_one == edge.point_one && point_two == edge.point_two;
            var samePointsReversed = point_one == edge.point_two && point_two == edge.point_one;
            if (samePointsReversed)
            {
                this.eaqalEdge = edge;
                edge.eaqalEdge=this;
            }
            return samePoints || samePointsReversed;
        }
        public Edge(Point orgin, Point source)
        {
            this.point_one = orgin;
            this.point_two = source;
        }
    }
    public class Triangle: Polygon
    {
        public Edge[] edges=new Edge[3];
        public  bool stard=true;
        private Cicle circumcircle = new Cicle();
        public Cicle Circumcircle
        {
            get { return circumcircle; }
        }
        /// <summary>
        /// 请输入的点按顺时针传入
        /// </summary>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <param name="point3"></param>
        public Triangle(Point point1, Point point2, Point point3)
        {
            this.points = new Point[3];
            this.points[0] = point1;
            this.points[1] = point2;
            this.points[2] = point3;
            get_CircumcircleInfo();
            this.edges[0] = new Edge(point1, point2);
            this.edges[1] = new Edge(point2, point3);
            this.edges[2] = new Edge(point3, point1);
            //var a=   this.edges.Select(o=>o.ownerTriangle = this).ToArray();
            this.edges[0].ownerTriangle =this;
            this.edges[1].ownerTriangle =this;
            this.edges[2].ownerTriangle =this;
        }

        /// <summary>
        ///  计算三角形外接圆心坐标和半径
        /// </summary>       
        private void get_CircumcircleInfo()
        {
            double x1 = points[0].x, y1 = points[0].y, x2 = points[1].x, y2 = points[1].y, x3 = points[2].x, y3 = points[2].y;
            double D = 2 * (y1 * x3 + y2 * x1 - y2 * x3 - y1 * x2 - y3 * x1 + y3 * x2);
            double x = (y2 * x1 * x1 - y3 * x1 * x1 - y2 * y2 * y1 + y3 * y3 * y1 + x2 * x2 * y3 + y1 * y1 * y2 + x3 * x3 * y1 - y3 * y3 * y2 - x3 * x3 * y2 - x2 * x2 * y1 + y2 * y2 * y3 - y1 * y1 * y3) / D;
            double y = (x1 * x1 * x3 + y1 * y1 * x3 + x2 * x2 * x1 - x2 * x2 * x3 + y2 * y2 * x1 - y2 * y2 * x3 - x1 * x1 * x2 - y1 * y1 * x2 - x3 * x3 * x1 + x3 * x3 * x2 - y3 * y3 * x1 + y3 * y3 * x2) / D;
            double r = Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
            circumcircle.center = new Point(x, y);
            circumcircle.radius = (float)r;
        }


    }
}



